package com.sxpcwlkj.wx.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
//import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 品创网络
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "pay.wx")
public class WxProperties {
    //appId  开放平台/小程序/公众号等
    private String appId;
    //appSecret  开放平台/小程序/公众号等
    private String appSecret;
    //mchId 微信商户号和appid有签约关系
    private String mchId;
    //mchKey 微信商户秘钥
    private String mchApiKey;
    // 微信商户  证书
    private String keyPath;
    // 微信商户  证书
    private String certPath;

    private String notifyUrl;


    @Bean
    public WxMaConfig wxMaConfig() {
//        WxMaInMemoryConfig config = new WxMaInMemoryConfig();
//        config.setAppid(appId);
//        config.setSecret(appSecret);
        return null;
    }


    @Bean
    public WxMaService wxMaService(WxMaConfig maConfig) {
//        WxMaService service = new WxMaServiceImpl();
//        service.setWxMaConfig(maConfig);
        return null;
    }

    @Bean
    public WxPayConfig wxPayConfig() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(appId);
        payConfig.setMchId(mchId);
        payConfig.setMchKey(mchApiKey);
        payConfig.setNotifyUrl(notifyUrl);
        payConfig.setKeyPath(keyPath);
        payConfig.setTradeType("JSAPI");
        payConfig.setSignType("MD5");
        return payConfig;
    }


    @Bean
    public WxPayService wxPayService(WxPayConfig payConfig) {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }

}
